import myRequest from '@/request.js'
//0-计量单位；1-运输方式；2-场景标签；3-参数名称；4-产品标签；5-行业标签；6-材质；7-编型；
let arr = ['unitTypes', 'transportType', 'sceneType', 'parameterType', 'prolabelType', 'industryType', 'materialType', 'weaveType']
let obj = {
	muTypes: [
		{id: 100, name: 100},
		{id: 200, name: 200},
		{id: 300, name: 300},
		{id: 400, name: 400},
		{id: 500, name: 500},
		{id: 1000, name: 1000},
	]
}

function setConfig(val) {
	return new Promise((resolve) => {
		myRequest.post('mp/config/list',{},{token: true}).then(res => {
			if (res.success && res.msg.list && res.msg.list.length) {
				let data = res.msg.list
				arr.forEach(item => {
					obj[item] = []
				})
				data.forEach(e => {
					arr.forEach((item, index) => {
						if (e.type == index&&e.isshow) {
							obj[item].push(e)
						}
					})
				})
				resolve(obj)
			}else{
				resolve(obj)
			}
			uni.setStorageSync('config',obj)
		}).catch(()=>{
			resolve(obj)
		})
	})
}

export default {
	setConfig,
}